package org.fly.service.impl;

import org.fly.bean.AliSmsSetting;
import org.fly.bean.query.AliSmsSettingQuery;
import org.fly.dao.AliSmsSettingDao;
import org.fly.service.AliSmsSettingService;
import org.fly.utils.UUIDFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.fly.bean.common.BusinessException;
import java.util.List;

/**
* Created by autoCode on 2018-04-17 15:16:44.
*/
@Service
public class AliSmsSettingServiceImpl implements AliSmsSettingService {

    @Autowired
    AliSmsSettingDao aliSmsSettingDao;

    @Override
    public List<AliSmsSetting> list(AliSmsSettingQuery query) {
        return aliSmsSettingDao.list(query);
    }

    @Override
    public long count(AliSmsSettingQuery query) {
        return aliSmsSettingDao.count(query);
    }

    @Override
    public AliSmsSetting findById(String id) {
        return aliSmsSettingDao.findById(id);
    }

    @Override
    public AliSmsSetting find() {
        return aliSmsSettingDao.find();
    }

    @Override
    public void save(AliSmsSetting bean)  throws BusinessException {

    if(StringUtils.isNotBlank(bean.getId())){
         aliSmsSettingDao.update(bean);
    }else {
        bean.setId(UUIDFactory.random());
        bean.setCreateTime(System.currentTimeMillis());
        aliSmsSettingDao.insert(bean);
    }
    }

    @Override
    public void delete(String id) {
        aliSmsSettingDao.delete(id);
    }
}
